package com.bw.controller;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.bw.service.DataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @author Lenovo
 * @date 2025年09月05日 15:58
 */
@RestController
public class DataController {
    @Autowired
    private DataService dataService;
    @RequestMapping("/s1")
    public JSONObject select1(){
        JSONObject retult = new JSONObject();
        retult.put("status",0);
        retult.put("msg","");
        JSONObject data = new JSONObject();
        retult.put("data",data);

        JSONArray categories = new JSONArray();
        JSONArray series = new JSONArray();
        data.put("categories",categories);
        data.put("series",series);


        JSONObject col1 = new JSONObject();
        col1.put("name","name");
        JSONArray col1data = new JSONArray();
        col1.put("data",col1data);
        series.add(col1);

        JSONObject col2 = new JSONObject();
        col2.put("name","name");
        JSONArray col2data = new JSONArray();
        col2.put("data",col2data);
        series.add(col2);


        List<Map<String,Object>> maps=dataService.select1();
        for (Map<String, Object> map : maps) {
            categories.add(map.get("name"));
            col1data.add(map.get("cta"));
            col2data.add(map.get("ctb"));
        }
        return retult;
    }

    @RequestMapping("/s2")
    public JSONObject select2(){
        JSONObject retult = new JSONObject();
        retult.put("status",0);
        retult.put("msg","");
        JSONObject data = new JSONObject();
        retult.put("data",data);

        JSONArray columns = new JSONArray();
        JSONArray rows = new JSONArray();
        data.put("columns",columns);
        data.put("rows",rows);

        JSONObject col6 = new JSONObject();
        col6.put("name","下单金额");
        col6.put("id","cta");


        JSONObject col7 = new JSONObject();
        col7.put("name","下单次数");
        col7.put("id","ctb");




        columns.add(col6);
        columns.add(col7);




        List<Map<String,Object>>maps=dataService.select2();
        for (Map<String, Object> map : maps) {
            JSONObject row = new JSONObject();
            row.put("cta",map.get("cta"));
            row.put("ctb",map.get("ctb"));


            rows.add(row);
        }



        return retult;
    }

    @RequestMapping("/s3")
    public JSONObject select3(){
        JSONObject retult = new JSONObject();
        retult.put("status",0);
        retult.put("msg","");
        JSONObject data = new JSONObject();
        retult.put("data",data);

        JSONArray columns = new JSONArray();
        JSONArray rows = new JSONArray();
        data.put("columns",columns);
        data.put("rows",rows);

        JSONObject col1 = new JSONObject();
        col1.put("name","下单金额");
        col1.put("id","cta");

        JSONObject col2 = new JSONObject();
        col2.put("name","下单次数");
        col2.put("id","ctb");

        JSONObject col3 = new JSONObject();
        col3.put("name","下单次数");
        col3.put("id","ctc");

        JSONObject col4 = new JSONObject();
        col4.put("name","下单次数");
        col4.put("id","ctd");

        columns.add(col1);
        columns.add(col2);
        columns.add(col3);
        columns.add(col4);



        List<Map<String,Object>>maps=dataService.select3();
        for (Map<String, Object> map : maps) {
            JSONObject row = new JSONObject();
            row.put("cta",map.get("cta"));
            row.put("ctb",map.get("ctb"));
            row.put("ctc",map.get("ctc"));
            row.put("ctd",map.get("ctd"));
            rows.add(row);
        }
        return retult;
    }

    @RequestMapping("/s4")
    public JSONObject select4(){
        JSONObject retult = new JSONObject();
        retult.put("status",0);
        retult.put("msg","");
        JSONObject data = new JSONObject();
        retult.put("data",data);

        JSONArray categories = new JSONArray();
        JSONArray series = new JSONArray();
        data.put("categories",categories);
        data.put("series",series);


        JSONObject col1 = new JSONObject();
        col1.put("name","name");
        JSONArray col1data = new JSONArray();
        col1.put("data",col1data);
        series.add(col1);

        JSONObject col2 = new JSONObject();
        col2.put("name","name");
        JSONArray col2data = new JSONArray();
        col2.put("data",col2data);
        series.add(col2);

        JSONObject col3 = new JSONObject();
        col3.put("name","name");
        JSONArray col3data = new JSONArray();
        col3.put("data",col3data);
        series.add(col3);


        List<Map<String,Object>> maps=dataService.select4();
        for (Map<String, Object> map : maps) {
            categories.add(map.get("name"));
            col1data.add(map.get("cta"));
            col2data.add(map.get("ctb"));
            col3data.add(map.get("ctc"));
        }
        return retult;
    }

    @RequestMapping("/s5")
    public JSONObject selelct5(){
        JSONObject retult = new JSONObject();
        retult.put("status",0);
        retult.put("msg","");

        JSONArray data = new JSONArray();
        retult.put("data",data);

        List<Map<String,Object>>maps=dataService.select2();
        for (Map<String, Object> map : maps) {
            JSONObject row = new JSONObject();
            row.put("name",map.get("name"));
            row.put("value",map.get("cta"));
            row.put("value",map.get("ctb"));
            row.put("value",map.get("ctc"));
            row.put("value",map.get("cte"));
            data.add(row);
        }


        return retult;
    }
}
